<?php
declare (strict_types=1);

namespace app\admin\model\iot;

use app\BaseModel;

/**
 * 设备异常日志表
 */
class DeviceLogError extends BaseModel
{

    /**
     * 获取设备异常日志列表
     * @param array $where
     * @param int $page
     * @param int $limit
     * @param string $orderby
     * @return array
     */
    public static function getList(array $where, int $page, int $limit, string $orderby = ''): array
    {
        $data = self::where($where)
            ->order($orderby)
            ->paginate(['list_rows' => $limit, 'page' => $page], false)
            ->toArray();
        return $data;
    }

    /**
     * 写入设备异常日志
     * @param string $Imei
     * @param int $event
     * @param string $content
     * @return bool
     */
    public static function writeDeviceErrorLog(string $Imei, int $event, string $content = ''): bool
    {
        $data = [
            'imei' => $Imei,
            'event' => $event,
            'content' => $content,
            'create_time' => time(),
        ];
        $model = new self();
        return $model->save($data);
    }

}




